package com.exam.alibaba;

/**
 * date:
 * description:
 */
public class Solution005 {
    boolean isHappy(int num){
        String str = String.valueOf(num);
        String cur = str;
        while(true){
            int next = 0;
            for (int i = 0; i < cur.length(); i++) {
                next += (int) Math.pow(cur.charAt(i) - '0', 2);
            }
            if(next == 1){
                return true;
            }
            if(String.valueOf(next).equals(str)){
                return false;
            }
            cur = String.valueOf(next);
        }
    }

    public static void main(String[] args) {
        int num = 28;
        boolean res = new Solution005().isHappy(num);
        System.out.println(res);
    }
}
